﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace dzs.Web.supply
{
    public partial class AddProject : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindDDL();
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string proid = this.txtproid.Text;
            string projectName = this.txtprojectName.Text;
            DateTime beComplatedTime = DateTime.Parse(this.txtbeComplatedTime.Text);
            int projectTypeId = int.Parse(this.ddl_type.SelectedValue);
            //string status = this.txtstatus.Text;
            string levelType = this.ddl_level.SelectedValue;

            bool isComplated = false;

            if (this.ddl_isComplete.SelectedValue == "是")
            {
                isComplated = true;
            }

            Maticsoft.Model.project model = new Maticsoft.Model.project();
            model.proid = proid;
            model.projectName = projectName;
            model.beComplatedTime = beComplatedTime;
            model.projectTypeId = projectTypeId;
            //model.status = status;
            model.levelType = levelType;
            model.isComplated = isComplated;

            if (Session["login"] != null)
            {
                DataSet ds = Session["login"] as DataSet;

                int roles_id = Convert.ToInt32(ds.Tables[0].Rows[0]["roles_id"].ToString());
                int user_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"].ToString());

                model.uid = user_id;
            }

            Maticsoft.BLL.project bll = new Maticsoft.BLL.project();

            if (!bll.Exists(model.proid))
            {
                bll.Add(model);
                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "ListProject.aspx");
            }
            else
            {
                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "此项目编号已存在！无法新建", "AddProject.aspx");
            }

            
        }

        private void BindDDL()
        {
            Maticsoft.BLL.projectType pm = new Maticsoft.BLL.projectType();

            DataSet ds_type = pm.GetList("");

            this.ddl_type.DataSource = ds_type;
            this.ddl_type.DataTextField = "projectTypeName";
            this.ddl_type.DataValueField = "projectTypeId";
            this.ddl_type.DataBind();
        }
    }
}